home *** CD-ROM | disk | FTP | other *** search
- // Copyright: © 1993 Apple Computer, Inc. All rights reserved.
- // Victor J. Hnyp
- // Date: 11-Mar-93
-
- // Revisions
- //
- // 05/01/94 JAJ 2.09 Fixed: Stubbed all functiosn which used hard coded strings
- // for file names (isPrintMonitor, isAppleShare, isEtherTalk, & isTokenTAlk)
- // they were left in place for compatibility
- //
- // 03/11/93 VJH 2.08 Fixed: Removed EtherTalk Prep as required file for isEtherTalk
- //
- // 02/24/93 VJH 2.07 Fixed: Removed isSharedOwned context check
- //
- // 02/20/93 GB 2.06 Fixed: Setup ioNamePtr before calling PBHGetVInfo
- //
- // 02/08/93 VJH 2.05 Fixed: isControlPanel, isFileExists
- //
- // 01/18/93 VJH 2.04 Added: isFileExists
- //
- // 01/14/93 VJH 2.03 General RENO build update
- //
- // 12/21/92 VJH 2.02 Fixed: Typecast of PBGetCatInfo((CInfoPBPtr)&thePB) for stricter compile checking
- //
- // 11/29/92 VJH 2.01 Added: Is the frontmost (active) window the same name as the startup volume name?
- // Is the name of any open and visible window the same name as the startup volume name?
- // Is the current directory the startup disk's?
- // Is PrintMonitor installed?
- // Is AppleShare support software installed?
- // Is EtherTalk support software installed?
- // Is TokenTalk support software installed?
- // Is the Control Panel named "..." installed?
- // Is the shared folder whose path is "..." owned by the user?
- //
-
- #pragma load "AllHeaders.dump"
-
- #include "Utility.h"
- #include "Proto.h"
- #include "Context.h"
- #include "File.h"
-
-
- /* ------------------ Forward Declarations --------------------- */
- pascal Boolean IsFrontWindowStartupVol();
- pascal Boolean IsOpenWindowStartupVol();
- pascal Boolean IsCDOnStartupVol();
- pascal Boolean IsPrintMonitorInstalled();
- pascal Boolean IsAppleShareInstalled();
- pascal Boolean IsEtherTalkInstalled();
- pascal Boolean IsTokenTalkInstalled();
- pascal Boolean IsCPInstalled(FileStatePtr fileMsg);
- pascal Boolean IsFileInstalled(FileStatePtr fileMsg);
- OSErr FindSysFolder(short *foundVRefNum, long *foundDirID);
- OSErr FindExtFolder(short *foundVRefNum, long *foundDirID);
- OSErr FindFile(char *filename, short theVolume, long theDirID);
- short GetSFCurVol();
-
- pascal OSErr main(ContextSelectorPtr msg, Size inSize,
- void* outMessage, Size* outSize, Handle /*startGlobals*/)
- {
- Boolean ret = false;
- OSErr err = errAECorruptData;
-
- if(inSize < sizeof(ContextSelector)) /* If inSize is < length of selector (a long), */
- return(err); /* return an error. Would be nice to have a specific error # */
-
- switch (msg->selector)
- {
- case isFrontStartup: // Is the frontmost (active) window the same name as the startup volume name?
- ret = IsFrontWindowStartupVol();
- break;
-
- case isOpenStartup: // Is the name of any open and visible window the same name as the startup volume name?
- ret = IsOpenWindowStartupVol();
- break;
-
- case isCDStartup: // Is the current directory the startup disk's?
- ret = IsCDOnStartupVol();
- break;
-
- case isPrintMonitor: // Is PrintMonitor installed?
- break; // Always return false <JJ>
-
- case isAppleShare: // Is AppleShare support software installed?
- break; // Always return false <JJ>
-
- case isEtherTalk: // Is EtherTalk support software installed?
- break; // Always return false <JJ>
-
- case isTokenTalk: // Is TokenTalk support software installed?
- break; // Always return false <JJ>
-
- case isControlPanel: // Is the Control Panel named "..." installed?
- ret = IsCPInstalled((FileStatePtr)msg);
- break;
-
- case isFileExists: // Is the File named "..." within the system-defined folder ...?
- ret = IsFileInstalled((FileStatePtr)msg);
- break;
-
- default: /* None of the pre-defined types. Exit with error */
- return(err); /* Would be nice to have a specific error # */
- break;
- }
-
- err = SetContextResult(&ret, sizeof(Boolean), outMessage, outSize);
- return(err);
- }
-
-
- pascal Boolean IsFrontWindowStartupVol()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long systemDirID;
- VolumeParam thePB;
- WindowPtr wPtr;
- OSErr localError;
- Str255 winTitle;
- char nameString[32];
-
- if( FindSysFolder( &startupVolRefNum, &systemDirID )) // Error getting volume ref num of startup volume
- return( ret );
-
- /* Set the param block up for getting information about the startup volume */
- thePB.ioCompletion = nil;
- thePB.ioVolIndex = 0; // Use ioVRefNum field only
- thePB.ioVRefNum = startupVolRefNum; // Use the startup volume reference for lookup
- thePB.ioNamePtr = nameString;
-
- /* Get information on the startup volume SYNCHRONOUSLY, by passing pointer to our param block */
- if (localError = PBHGetVInfo((HParmBlkPtr)&thePB,false)) // Error getting information
- return( ret );
-
- wPtr = FrontWindow(); // Get frontmost window
- if( wPtr ) // If one exists, check if the name = startup volume name
- {
- GetWTitle(wPtr, winTitle); // Get the name of the window
- if(IUEqualString(winTitle, thePB.ioNamePtr) == 0) // Does the window name equal the directory name
- ret = true;
- }
-
- return( ret );
- } // IsFrontWindowStartupVol();
-
-
- pascal Boolean IsOpenWindowStartupVol()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long systemDirID;
- VolumeParam thePB;
- WindowPtr wPtr;
- OSErr localError;
- Str255 winTitle;
- char nameString[32];
-
- if( FindSysFolder( &startupVolRefNum, &systemDirID )) // Error getting volume ref num of startup volume
- return( ret );
-
- /* Set the param block up for getting information about the startup volume */
- thePB.ioCompletion = nil;
- thePB.ioVolIndex = 0; // Use ioVRefNum field only
- thePB.ioVRefNum = startupVolRefNum; // Use the startup volume reference for lookup
- thePB.ioNamePtr = nameString;
-
- /* Get information on the startup volume SYNCHRONOUSLY, by passing pointer to our param block */
- if (localError = PBHGetVInfo((HParmBlkPtr)&thePB,false)) // Error getting information
- return( ret );
-
- wPtr = FrontWindow(); // Get frontmost window
- while( wPtr ) // For all windows, check if name = startup volume name
- {
- GetWTitle(wPtr, winTitle); // Get the name of the window
- if(IUEqualString(winTitle, thePB.ioNamePtr) == 0) // Does the window name equal the directory name
- return( true );
- wPtr = (WindowPtr)((WindowPeek)wPtr)->nextWindow; // Go on to next window
- }
-
- return( ret );
- } // IsOpenWindowStartupVol();
-
-
- pascal Boolean IsCDOnStartupVol()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long systemDirID;
- short currentVol;
-
- if( FindSysFolder( &startupVolRefNum, &systemDirID )) // Error getting volume ref num of startup volume
- return( ret );
-
- currentVol = GetSFCurVol();
-
- return(currentVol == startupVolRefNum);
- } // IsCDOnStartupVol();
-
-
- pascal Boolean IsPrintMonitorInstalled()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long extensionsDirID;
-
- if( FindExtFolder( &startupVolRefNum, &extensionsDirID )) // Error getting volume ref num or extensions directory ID
- return( ret );
-
- if( FindFile( "\pPrintMonitor", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsPrintMonitorInstalled();
-
-
- pascal Boolean IsAppleShareInstalled()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long extensionsDirID;
-
- if( FindExtFolder( &startupVolRefNum, &extensionsDirID )) // Error getting volume ref num or extensions directory ID
- return( ret );
-
- if( FindFile( "\pAppleShare", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsAppleShareInstalled();
-
-
- pascal Boolean IsEtherTalkInstalled()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long extensionsDirID;
-
- if( FindExtFolder( &startupVolRefNum, &extensionsDirID )) // Error getting volume ref num or extensions directory ID
- return( ret );
-
- if( FindFile( "\pNetwork Extension", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- if( FindFile( "\pEtherTalk Phase 2", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsEtherTalkInstalled();
-
-
- pascal Boolean IsTokenTalkInstalled()
- {
- Boolean ret = false;
- short startupVolRefNum;
- long extensionsDirID;
-
- if( FindExtFolder( &startupVolRefNum, &extensionsDirID )) // Error getting volume ref num or extensions directory ID
- return( ret );
-
- if( FindFile( "\pNetwork Extension", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- if( FindFile( "\pTokenTalk", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- if( FindFile( "\pA/ROSE", startupVolRefNum, extensionsDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsEtherTalkInstalled();
-
-
- pascal Boolean IsCPInstalled(FileStatePtr fileMsg)
- {
- Boolean ret = false;
- short startupVolRefNum;
- long controlPanelsDirID;
-
- startupVolRefNum = 0;
- controlPanelsDirID = 0;
-
- if( FindFolder( kOnSystemDisk, kControlPanelFolderType, kDontCreateFolder, &startupVolRefNum, &controlPanelsDirID ))
- return( ret );
-
- if( FindFile( fileMsg->fileName.str, startupVolRefNum, controlPanelsDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsCPInstalled();
-
-
- pascal Boolean IsFileInstalled(FileStatePtr fileMsg)
- {
- Boolean ret = false;
- short startupVolRefNum;
- long theDirID;
-
- startupVolRefNum = 0;
- theDirID = 0;
-
- if( FindFolder( kOnSystemDisk, fileMsg->sysFolderCode, kDontCreateFolder, &startupVolRefNum, &theDirID ))
- return( ret );
-
- if( FindFile( fileMsg->fileName.str, startupVolRefNum, theDirID )) // Error finding the file
- return( ret );
-
- return( true ); // File was found OK
- } // IsCPInstalled();
-
-
- OSErr FindSysFolder(short *foundVRefNum, long *foundDirID)
- {
- OSErr err;
-
- *foundVRefNum = 0;
- *foundDirID = 0;
- err = FindFolder( kOnSystemDisk, kSystemFolderType, kDontCreateFolder, foundVRefNum, foundDirID );
- return( err );
- } // FindSysFolder();
-
-
- OSErr FindExtFolder(short *foundVRefNum, long *foundDirID)
- {
- OSErr err;
-
- *foundVRefNum = 0;
- *foundDirID = 0;
- err = FindFolder( kOnSystemDisk, kExtensionFolderType, kDontCreateFolder, foundVRefNum, foundDirID );
- return( err );
- } // FindExtFolder();
-
-
- OSErr FindFile(char *filename, short theVolume, long theDirID)
- {
- OSErr err;
- HFileInfo thePB;
-
- /* Set the param block up for getting information about the given file */
- thePB.ioCompletion = nil;
- thePB.ioNamePtr = filename; // File name we want
- thePB.ioVRefNum = theVolume; // Volume to be searched
- thePB.ioFDirIndex = 0; // Use the filename to find our file
- thePB.ioDirID = theDirID; // The directory to be searched
-
- if (err = PBGetCatInfo((CInfoPBPtr)&thePB,false)) // Error getting information
- return( err );
-
- return( 0 );
- } // FindFile();
-
-
- short GetSFCurVol()
- {
- short volRef;
-
- volRef = (short*)SFSaveDisk;
- volRef = -volRef;
- return( volRef );
- }
-